package com.ruoyi.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 运单状态
 *
 * @author Fgxia LD 99
 */
@Getter
@AllArgsConstructor
public enum FreightStatus {
    INITIALIZED("0", "初始化"),

    WAITING_FOR_PICKUP("1","待提货"),

    DELIVERING("2", "配送中"),

    WAITING_FOR_RECEIPT("3","待回单"),

    WAITING_FOR_PAYMENT("4","待打款"),

    COMPLETED("5","已完成")
    ;

    private final String code;

    private final String info;

    /**
     * 判断传入的状态是否在当前状态之后
     *
     * @return 如果传入的状态在当前状态之后，则返回true，否则返回false
     */
    public boolean isBefore(FreightStatus checkStatus) {
        // 将状态码转换为整数进行比较
        int currentStatusCode = Integer.parseInt(this.code);
        int statusCodeToCheck = Integer.parseInt(checkStatus.getCode());

        return currentStatusCode < statusCodeToCheck;
    }

    /**
     * 通过状态码获取对应的FreightStatus枚举
     *
     * @param code 状态码
     * @return 对应的FreightStatus枚举，如果没有找到则返回null
     */
    public static FreightStatus fromCode(String code) {
        for (FreightStatus status : FreightStatus.values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }
}
